import { EffectFA } from './effect-fa';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { catchError, retry } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { NgxhttpService } from '../../../@core/utils/ngxhttp.service';
import { Router } from '@angular/router';
import { NbTokenService } from '@nebular/auth';
@Injectable()
export class EffectService extends NgxhttpService {
  configUrl: string = "assets/pages/main/effect1.json";
  configeffect1: string = 'assets/pages/main/effect1.json';
  configeffect10: string = 'assets/pages/main/effect10.json';
  configeffect20: string = 'assets/pages/main/effect20.json';
  constructor(private http: HttpClient,
    tokenService: NbTokenService,
    router: Router) {
    super(tokenService, router);
  }
  getFAList(dataType: string): Observable<EffectFA[]> {
    console.log(dataType);
    if (dataType == '0')
      this.configUrl = this.configeffect1;
    else if (dataType == '1')
      this.configUrl = this.configeffect10;
    else if (dataType == '2')
      this.configUrl = this.configeffect10;
    else
      this.configUrl = this.configeffect20;
    return this.http.get<EffectFA[]>(this.configUrl).pipe(
      retry(1), // retry a failed request up to 3 times
      catchError((error: HttpErrorResponse) =>
        this.handleError(error)
      ) // then handle the error
    );
  }
}
